package com.shenghui.enterprise.enterprise.front.controller;
import com.shenghui.enterprise.enterprise.entity.EntBasicInfo;
import com.shenghui.enterprise.enterprise.service.IEntBasicInfoService;
import com.shenghui.enterprise.utils.GeneralUtil;
import com.shenghui.enterprise.utils.UserUtil;
import com.shenghui.enterprise.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import java.util.Map;

/**
 * @Description: 企业基础信息表 前端控制器
 * @Author tt
 * @Email: happyxiaohou@gmail.com
 * @Date: 2020-10-13
 * @Copyright (c) 2020-2022 云南昇晖科技有限公司
 */
@RestController
@RequestMapping("/front/entBasicInfo" )
@Api(value = "企业基础信息表接口",description = "用作企业基础信息表演示")
public class FrontEntBasicInfoController {

    @Autowired
    private IEntBasicInfoService entBasicInfoService;
    @Autowired
    private UserUtil userUtil;

    /**
     * 用户注册
     * @param entBasicInfo
     * @return
     */
    @RequestMapping("/register")
    public Result register(EntBasicInfo entBasicInfo){
        if(GeneralUtil.isNull(entBasicInfo)){
            return Result.error("参数信息不能为空!");
        }
        if(GeneralUtil.isNull(entBasicInfo.getUserAccount())){
            return Result.error("用户名不能为空!");
        }
        if(GeneralUtil.isNull(entBasicInfo.getEntName())){
            return Result.error("单位名称不能为空!");
        }
        if(GeneralUtil.isNull(entBasicInfo.getEntCode())){
            return Result.error("统一社会信息代码不能为空!");
        }
        if(GeneralUtil.isNull(entBasicInfo.getLegalPerson())){
            return Result.error("法定代表人不能为空!");
        }
        if(GeneralUtil.isNull(entBasicInfo.getEntProperty())){
            return Result.error("单位性质不能为空!");
        }
        if(GeneralUtil.isNull(entBasicInfo.getRegisterTimeStr())){
            return Result.error("注册日期不能为空!");
        }
        if(GeneralUtil.isNull(entBasicInfo.getRegisterAddress())){
            return Result.error("注册地址不能为空!");
        }
        if(GeneralUtil.isNull(entBasicInfo.getPwd())){
            return Result.error("密码不能为空!");
        }
        return entBasicInfoService.register(entBasicInfo);
    }

    /**
     * 获取企业基本信息
     * @return
     */
    @RequestMapping("/getLoginEntBasicInfo")
    public Result getLoginEntBasicInfo(){
        EntBasicInfo frontLoginUser = userUtil.getFrontLoginUser();
        return Result.ok("查询成功",frontLoginUser);
    }

    /**
     * 重置密码
     * @param map
     * @return
     */
    @RequestMapping("/resetPassword")
    public Result resetPassword(@RequestParam Map map){
        if(GeneralUtil.isNull(map)){
            return Result.error("参数不能为空");
        }
        if(GeneralUtil.isNull(map.get("oldPass"))){
            return Result.error("旧密码不能为空");
        }
        if(GeneralUtil.isNull(map.get("newPass"))){
            return Result.error("密码不能为空");
        }
        return entBasicInfoService.resetPassword(map);
    }

}
